/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("IngredientsArea",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using Mercury.Entity.DomainModels;
using Mercury.Business.IServices;
using Mercury.Core.Utilities;
using Mercury.Business.IRepositories;
using Mercury.Core.BaseProvider;
using System.Linq;

namespace Mercury.Business.Controllers
{
    public partial class IngredientsAreaController
    {
        private readonly IIngredientsAreaService _service;//访问业务代码
        private readonly IIngredientsAreaRepository _repository;
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public IngredientsAreaController(
            IIngredientsAreaService service,
            IIngredientsAreaRepository repository ,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _repository = repository;
            _httpContextAccessor = httpContextAccessor;
        }


        [Route("GetIngredientAreas"), HttpGet]
        public async Task<WebResponseContent> GetIngredientAreas()
        {
            var areas = await _repository.FindAsync(c => c.State == 1);
            var data = areas.GroupBy(c=>c.Region).Select(c => new { Id = c.Key, Region = c.Key, ParentId = "-" });
            return new WebResponseContent() { Status = true, Data = data };
        }
    }
}
